package com.lswms.modules.lswms.controller.api;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lswms.modules.lswms.entity.task.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lswms.common.utils.Result;
import com.lswms.modules.lswms.service.base.SequenceService;
import com.lswms.modules.lswms.service.task.TaskService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * API
 *
 * @author DX
 * @since 1.0.0 2021-06-26
 */
@RestController
@RequestMapping("API")
@Api(tags="API")
public class APIController {

	@Autowired
	SequenceService sequenceService;

	@Autowired
	TaskService taskService;

    @GetMapping("getPLN")
    @ApiOperation("信息")
    public Result getPLN( @RequestParam Map<String, Object> params){

    	String type =(String) params.get("type");
    	Integer count =Integer.valueOf((String) params.get("count"));


		/*
		 * 中托盘 MTRAY 大托盘 LTRAY 小托盘 STRAY
		 */

    	List<Map<String,Object>>  lpnList = new ArrayList<Map<String,Object>>();

    	for(int i=0 ;i<count ;i++) {
    		String  lpn = sequenceService.getSequence(type) ;

    		Map<String,Object> returnMap = new HashMap<String, Object>();
    		returnMap.put("LPN", lpn);


    		lpnList.add(returnMap);
    	}

//
//    	Map<String,Object> returnMap = new HashMap<String, Object>();
//    	returnMap.put("data", lpnList) ;
//    	returnMap.put("total", count) ;
//    	returnMap.put("count", count) ;
    	Result result = new Result().ok(lpnList) ;
    	return   result ;
    }

	@GetMapping("/visualization")
	public Result visualizationTask(){
		//Map<String, Integer> statusList = taskService.getStatusList();

//		return new Result().ok(statusList);
		return new Result();
	}
	
	@GetMapping("/taskStatus")
	public Result taskStatus(){
		List<Map<String, Object>> statusList = taskService.getStatusList();

		return new Result().ok(statusList);
	}
	
	@GetMapping("/getLocationUse")
	public Result getLocationUse(){
		List<Map<String, Object>> LocationUseList = taskService.getLocationUse();
		
		Integer skuSum = taskService.getSkuSum();
		
		BigDecimal weigth = taskService.getWeigth();
		//获取总库为和以及使用的库位
		Integer locateCount = taskService.getlocateCount();
		Integer locateSY = taskService.getlocateSY();

		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("location", LocationUseList);
		returnMap.put("skuSum", skuSum);
		returnMap.put("weigth", weigth);
		returnMap.put("locateCount",locateCount);
		returnMap.put("locateSY",locateSY);
		
		return new Result().ok(returnMap);
	}
	
	@GetMapping("/getSkuCount")
	public Result getSkuCount(){
		Map<String, BigDecimal> skuCountMap = taskService.getSkuCount();

		return new Result().ok(skuCountMap);
	}

	@GetMapping("/getDDJStatus")
	public Result getDDJStatus(){
		List<Map<String, Object>> ddjStatusMap = taskService.getDDJStatus();

		return new Result().ok(ddjStatusMap);
	}
	
	@GetMapping("/getLast7Days")
	public Result getLast7Days(){
		Map<String , Object> last7DaysMap = taskService.getLast7Days();

		return new Result().ok(last7DaysMap);
	}
	
	@GetMapping("/getLast30Days")
	public Result getLast30Days(){
		Map<String , Object> last30DaysMap = taskService.getLast30Days();

		return new Result().ok(last30DaysMap);
	}
	
	@GetMapping("/getLastYear")
	public Result getLastYear(){
		Map<String , Object> dataMap = taskService.getLastYear();

		return new Result().ok(dataMap);
	}

	@GetMapping("/getInventorAlarm")
	public Result getInventorAlarm(){
		List<Map<String, Object>> dataMap = taskService.getInventorAlarm();
		return new Result().ok(dataMap);
	}
	
	@GetMapping("/getTodayTaskInfo")
	public Result getTodayTaskInfo(){
		List<Map<String, Object>> dataMap = taskService.getTodayTaskInfo();
		return new Result().ok(dataMap);
	}

	@GetMapping("/getTodayTaskInfo2")
	public Result getTodayTaskInfo2(@RequestParam Map<String ,Object> parmet){
		IPage<TaskEntity> dataMap2 = taskService.getTodayTaskInfo2(parmet);
		return new Result().ok(dataMap2);
	}
}
